
#include <dev.h>
#include "pci.h"

/* ------------------------------------------------------------------------- */

static pci_dev_t isa_dev;

static void fastcall isa_config(uint8 reg, uint32 data, uint32 mask);
static size_t fastcall isa_map_size(uint map);
static size_t fastcall isa_read_map(uint map, uint32 addr, void *data, size_t size);
static size_t fastcall isa_write_map(uint map, uint32 addr, const void *data, size_t size);

/* ------------------------------------------------------------------------- */

pci_dev_t *get_isa_device(void)
{
	memset(&isa_dev, 0, sizeof(isa_dev));

#ifndef NDEBUG
	strcpy(isa_dev.name, "ISA");
#endif

	isa_dev.conf.hdr.type0.base_addr[0] = PCI_BASE_ADDR_IO;

	isa_dev.config = &isa_config;
	isa_dev.map_size = &isa_map_size;
	isa_dev.read_map = &isa_read_map;
	isa_dev.write_map = &isa_write_map;

	return &isa_dev;
}

/* ------------------------------------------------------------------------- */

static void fastcall isa_config(uint8 reg, uint32 data, uint32 mask)
{
	if (reg == 0x80) {
		reg = (reg - PCI_CONFIG_HEADER_SIZE) >> 2;
		isa_dev.conf.data[reg] = data;
		set_mcpx_map(!(data & 0x00000002));
	}
}

static size_t fastcall isa_map_size(uint map)
{
	if (map == 0)
		return 0x100;

	return 0;
}

static size_t fastcall isa_read_map(uint map, uint32 addr, void *data, size_t size)
{
	return size;
}

static size_t fastcall isa_write_map(uint map, uint32 addr, const void *data, size_t size)
{
	return size;
}

/* ------------------------------------------------------------------------- */
